import { ref, nextTick } from 'vue'
import { defineStore } from 'pinia'
import type Footer from '@/views/testH5/footer.vue'

export const useTestH5Store = defineStore('testH5', () => {
  const messages = ref<string[]>([])
  const pageRef = ref<HTMLDivElement | null>(null)
  const contentRef = ref<HTMLDivElement | null>(null)
  const footerRef = ref<InstanceType<typeof Footer> | null>(null)
  const inputRef = ref<HTMLDivElement | null>(null)

  const addMessage = (message: string) => {
    messages.value.push(message)
  }

  const handleSend = (text: string) => {
    messages.value.push(text)
    
    // 滚动到底部
    nextTick(() => {
      if (contentRef.value) {
        contentRef.value.scrollTop = contentRef.value.scrollHeight
      }
    })
  }

  return { 
    messages, 
    pageRef,
    contentRef,
    footerRef,
    inputRef,
    addMessage,
    handleSend
  }
})
